<?php
require(__DIR__ . "/../bootstrap.php");

// Construct the FDS client
$access_key = "5411744243597";
$access_secret = "hu/XTi7mhl1j+pL5qkQGnw==";
$credential = new \FDS\credential\BasicFDSCredential($access_key, $access_secret);
$fds_config = new \FDS\FDSClientConfiguration();
$fds_config->setRegionName("awsbj0");
$fds_config->enableHttps(true);
$fds_config->enableCdnForUpload(false);
$fds_config->enableCdnForDownload(true);

$fds_client = new \FDS\GalaxyFDSClient($credential, $fds_config);
$bucket_name = "test5";

require_once 'EasyMySQLi.inc.php';
$db = new EasyMySQLi('localhost', 'root', 'root', 'madv_db1');
try {
  $result=$db->queryAllRows('select t1.filename,t1.type,t1.appconfirm,t1.serverconfirm,file_transcode.resolution,file_transcode.videocodec,file_transcode.bitrate from (select * from file where file.appconfirm=-1 and file.serverconfirm=-1 and status >0) as t1 left join file_transcode on t1.filename=file_transcode.filename');
  if(!empty($result)){
    for($i=0;$i<count($result);$i++){
      if(!empty($result[$i]["filename"])){
        $object_name=$result[$i]['filename']."_".$result[$i]['resolution'].'_'.$result[$i]['videocodec'].'_'.$result[$i]['bitrate'].'.mp4';
        if($fds_client->doesObjectExist($bucket_name, $object_name)){
          $fds_client->deleteObject($bucket_name, $object_name);
        }
        if($result[$i]["type"]==1){
          if($fds_client->doesObjectExist($bucket_name, $result[$i]["filename"].".mp4")){
            $fds_client->deleteObject($bucket_name, $result[$i]["filename"].".mp4");
          }
        }else{
          if($fds_client->doesObjectExist($bucket_name, $result[$i]["filename"].".png")){

            $fds_client->deleteObject($bucket_name, $result[$i]["filename"].".png");
          }
        }
        $db->queryNoResult('update file set status=-3 where filename=?',$result[$i]["filename"]);//视频被删除-3
      }
    }
  }
}catch (MySQLiQueryException $ex) {
  //echo '{"rval":3}';// 失败
}
